package com.rentong.wx.cust.controller;

import com.rentong.common.R;

import com.rentong.wx.cust.domain.CustCanyinquanDianzanArticleEntity;
import com.rentong.wx.cust.domain.CustCanyinquanEntity;
import com.rentong.wx.cust.domain.CustCanyinquanPinglunEntity;
import com.rentong.wx.cust.dto.CustCanyinquanEntityDto;
import com.rentong.wx.cust.dto.SaveCanyinquanDto;
import com.rentong.wx.cust.service.CustCanyinquanService;
import com.rentong.wx.utils.WxApiUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * @author zhangle
 * @email 459343178@qq.com
 * @date 2024-12-24 14:42:33
 */
@RestController
public class CustCanyinquanController {

    @Autowired
    private CustCanyinquanService custCanyinquanService;


    //9、查看餐饮圈列表
    //sort，1：最新发布，2：热门头条，3：距离最近
    @GetMapping("/custCanyinquan/getCustCanyinquanList")
    public R getCustCanyinquanList(Long cityId, String content, BigDecimal longitude, BigDecimal latitude, Integer sort, Long canyinquanLabelId, Integer pageNum, Integer pageSize, HttpServletRequest request) throws Exception {
        Long custId = WxApiUtil.getCurrentCustId(request);
        return R.success(custCanyinquanService.getCustCanyinquanList(cityId, content, longitude, latitude, sort, canyinquanLabelId, pageNum, pageSize, custId));
    }


    //10、查看动态详情内容
    @GetMapping("/custCanyinquan/getDynamicName")
    public R getDynamicName(HttpServletRequest request, Long canyinquanId) throws Exception {
        return R.success(custCanyinquanService.getDynamicName(WxApiUtil.getCurrentCustId(request), canyinquanId));
    }


    //11、查看动态详情评论
    @GetMapping("/custCanyinquan/getPingLun")
    public R getPingLun(Long canyinquanId, Integer pageNum, Integer pageSize, HttpServletRequest request) throws Exception {
        return R.success(custCanyinquanService.getPingLun(canyinquanId, WxApiUtil.getCurrentCustId(request), pageNum, pageSize));
    }


    //12、点击加载更多评论
    @GetMapping("/custCanyinquan/getChildPingLun")
    public R getLoadChildPingLun(Long canyinquanPinglunId, Integer pageNum, Integer pageSize, HttpServletRequest request) throws Exception {
        return R.success(custCanyinquanService.getLoadChildPingLun(canyinquanPinglunId, WxApiUtil.getCurrentCustId(request), pageNum, pageSize));
    }


    // 99、发布餐饮圈
    @PostMapping("/custCanyinquan/saveCanyinquan")
    public R saveCanyinquan(SaveCanyinquanDto saveCanyinquanDto, HttpServletRequest request) throws Exception {
        Long result = custCanyinquanService.saveCanyinquan(saveCanyinquanDto, WxApiUtil.getCurrentCustId(request));
        if (result>0) {
            return R.success(result);
        }
        return R.error("发布失败");
    }


    //201、餐饮圈详情页，下架、打电话、转发、删除
    @RequestMapping("/custCanyinquan/updateCanyinquanState")
    public R updateCanyinquanState(Long canyinquanId, Integer type, HttpServletRequest request) throws Exception {
        custCanyinquanService.updateCanyinquanState(canyinquanId, type, WxApiUtil.getCurrentCustId(request));
        return R.success("操作成功");
    }


    //202、餐饮圈详情页，点赞、取消点赞
    @RequestMapping("/custCanyinquan/updateOrDelDianzan")
    public R updateOrDelDianzan(Long canyinquanPinglunId, Integer type, HttpServletRequest request) throws Exception {
        custCanyinquanService.updateOrDelDianzan(canyinquanPinglunId, type, WxApiUtil.getCurrentCustId(request));
        return R.success("操作成功");
    }


    //306、餐饮圈详情页，评论
//    @PostMapping("/custCanyinquan/insertPinglun1")
//    public R insertPinglun(Long fuId,HttpServletRequest request,String pinglunContent,Long canyinquanId) throws Exception {
//        custCanyinquanService.insertPinglun(fuId, WxApiUtil.getCurrentCustId(request),pinglunContent,canyinquanId);
//        return R.success("操作成功");
//    }
    //203、餐饮圈详情页，评论
    @RequestMapping("/custCanyinquan/insertPinglun")
    public R insertPinglun(CustCanyinquanPinglunEntity custCanyinquanPinglunEntity, HttpServletRequest request) throws Exception {
        custCanyinquanPinglunEntity.setCustId(WxApiUtil.getCurrentCustId(request));
        custCanyinquanService.insertPinglun(custCanyinquanPinglunEntity);
        return R.success("操作成功");
    }

    //207、我的餐饮圈，展示信息列表
    @RequestMapping("/custCanyinquan/getCanyinquanList")
    public R getCanyinquanList(CustCanyinquanEntityDto custCanyinquanEntityDto, HttpServletRequest request) throws Exception {
        custCanyinquanEntityDto.setCustId(WxApiUtil.getCurrentCustId(request));
        return R.success(custCanyinquanService.getCanyinquanList(custCanyinquanEntityDto));
    }

    //234、修改我的餐饮圈发布的内容
    @RequestMapping("/custCanyinquan/updateCanyinquanById")
    public R updateCanyinquanById(CustCanyinquanEntityDto custCanyinquanEntityDto, HttpServletRequest request) throws Exception {
        custCanyinquanEntityDto.setCustId(WxApiUtil.getCurrentCustId(request));
        custCanyinquanService.updateCanyinquanById(custCanyinquanEntityDto);
        return R.success("操作成功！");
    }

    //130、餐饮圈列表点赞或取消点赞
    @PostMapping("/custCanyinquan/insertDelDianzan")
    public R insertDelDianzan(HttpServletRequest request, CustCanyinquanDianzanArticleEntity cdae, Integer type) throws Exception {
        Long custId = WxApiUtil.getCurrentCustId(request);
        cdae.setCustId(custId);
        return R.success(custCanyinquanService.insertDelDianzan(cdae, type));
    }

}
